home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: jdmorris@ix.netcom.com (Jason D. Morris)
- Newsgroups: comp.lang.c++,comp.lang.c,comp.object,comp.software-eng
- Subject: Re: Pointers are hacks in c++ (portablity hackers etc)
- Date: Tue, 26 Mar 1996 02:53:55 GMT
- Organization: Netcom
- Message-ID: <31575aa3.33876812@nntp.ix.netcom.com>
- References: <4ikb6kINN1is@mayne.ugrad.cs.ubc.ca> <DoI5Ao.AyJ@assip.csasyd.oz> <EJH.96Mar19163745@larry.gsfc.nasa.gov> <vpwa1m6wu.fsf_-_@jlbaker.async.csuohio.edu>
- NNTP-Posting-Host: pon-mi4-02.ix.netcom.com
- X-NETCOM-Date: Mon Mar 25 6:53:01 PM PST 1996
- X-Newsreader: Forte Agent .99d/32.182
-
- >I'm posting because I think I see a disturbing trend in c++.
- >Programmers seem to have an unreasoning fear of pointers in general:
- >An stl object lives in exactly one container, exactly one auto_ptr
- >points at any object and reference counting mechanisms seem aimed at
- >efficiently giving you a private object rather than sharing an object
- >without leakage. With these constructs, you can have only one
- >reference to a new'ed object, something I find antithetical to the
- >very notion of a pointer.
-
- It's not a fear, per se, but rather an understanding of the havoc
- pointers can wreak. There are really two issues concerning pointers,
- their use in the presence of exceptions (ensuring that allocated
- resources are properly allocated). The use of pointers in
- class/function interfaces and who has ownership. The first problem is
- addressed by the auto_ptr class. The second is can be addressed by
- using references in interfaces rather than pointers. When a reference
- is used, there is no question of ownership. The caller *always*
- retains ownership and *always* is responsible for deallocating the
- resource. The only time I can think of when a pointer is acceptable
- in an interface is when and object/function must retain a reference to
- another object and that reference has the ability to change. I
- suppose one could consider pointers to functions as acceptable.
- Essentially, all other uses for pointers are best left to the internal
- implementation of and object/function where the maintainer of the
- object/function is aware of the details of the pointer's use and
- allocation/deallocation policy.
-
- Jason
-
-